/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yutel.util;

import java.util.Hashtable;

/**
 *
 * @author yuanyajun
 */
public class LangUtil {
    //页面标题
    public static String tit_index = "title_1";
    public static String tit_login = "title_2";
    public static String tit_query = "title_3";
    public static String tit_charge = "title_4";
    public static String tit_preferences = "title_5";
    public static String tit_register = "title_6";
    //页面标签
    public static String tag_account = "tag_1";
    public static String tag_alias = "tag_2";
    public static String tag_pwd = "tag_3";
    public static String tag_cardno = "tag_4";
    public static String tag_cardpwd = "tag_5";
    public static String tag_prepPhone = "tag_6";
    public static String tag_lang = "tag_7";
    public static String tag_autoLogin = "tag_8";
    public static String tag_rememberMe = "tag_9";
    //按钮
    public static String but_login = "button_1";
    public static String but_submit = "button_2";
    public static String but_quit = "button_3";
    public static String but_back = "button_4";
    public static String but_query = "button_5";
    public static String but_charge = "button_6";
    public static String but_option = "button_7";
    public static String but_register = "button_8";
    public static String but_logout = "button_9";
    public static String but_confirm = "button_10";
    //下拉列表
    public static String lang_en = "lang_1";
    public static String lang_zh_cn = "lang_2";
    //字符串
    public static String str_callee = "str_1";
    public static String str_charge = "Str_2";
    public static String str_alert = "Str_3";
    public static String str_alertText = "Str_4";
    public static String str_preCharge = "Str_5";
    private LangUtil() {
        this.lang = "zh_cn";
        load();
    }
    public static LangUtil instance = new LangUtil();

    public static LangUtil getInstance() {
        return instance;
    }
    private String lang;
    private Hashtable messages;

    public void setLang(String lang) {
        if (!this.lang.equals(lang)) {
            this.lang = lang;
            load();
        }
    }

    private void load() {
        DBUtil dbUtil = new DBUtil();
        Preference p = dbUtil.getPreference(2);
        if (p != null) {
            p.setLang(lang);
            dbUtil.savePreference(p, 2);
        }
        if (messages == null) {
            messages = new Hashtable();
        } else {
            messages.clear();
        }
        if ("zh_cn".equals(lang)) {
            zh_cn();
        } else {
            en();
        }
    }

    public String getMessage(String name) {
        Object o = messages.get(name);
        if (o == null) {
            return name;
        } else {
            return (String) o;
        }
    }

    private void zh_cn() {
        messages.put(tit_index, "预约电话");
        messages.put(tit_login, "用户登录");
        messages.put(tit_query, "费率查询");
        messages.put(tit_charge, "用户充值");
        messages.put(tit_preferences, "系统设置");
        messages.put(tit_register, "用户注册");
        messages.put(tag_account, "帐号");
        messages.put(tag_alias, "昵称");
        messages.put(tag_pwd, "密码");
        messages.put(tag_cardno, "卡号");
        messages.put(tag_cardpwd, "卡号密码");
        messages.put(tag_prepPhone, "预约电话");
        messages.put(tag_lang, "语言");
        messages.put(tag_autoLogin, "自动登录");
        messages.put(tag_rememberMe, "记住我");
        messages.put(but_login, "登录");
        messages.put(but_submit, "提交");
        messages.put(but_quit, "退出");
        messages.put(but_back, "返回");
        messages.put(but_query, "费率查询");
        messages.put(but_charge, "充值");
        messages.put(but_option, "设置");
        messages.put(but_register, "注册");
        messages.put(but_logout, "注销");
        messages.put(but_confirm, "确定");
        messages.put(lang_en, "英语");
        messages.put(lang_zh_cn, "汉语");
        messages.put(str_callee, "电话费率");
        messages.put(str_charge, "帐号充值");
        messages.put(str_alert, "操作提醒");
        messages.put(str_alertText, "确定后就会提交！");
        messages.put(str_preCharge, "帐号充值确认?");
    }

    private void en() {
        messages.put(tit_index, "Callee");
        messages.put(tit_login, "Login");
        messages.put(tit_query, "Cost Query");
        messages.put(tit_charge, "Charge");
        messages.put(tit_preferences, "Preferences");
        messages.put(tit_register, "Register");
        messages.put(tag_account, "Account");
        messages.put(tag_alias, "Alias");
        messages.put(tag_pwd, "Password");
        messages.put(tag_cardno, "Card NO");
        messages.put(tag_cardpwd, "Card Password");
        messages.put(tag_prepPhone, "Callee");
        messages.put(tag_lang, "language");
        messages.put(tag_autoLogin, "Auto Login");
        messages.put(tag_rememberMe, "Remember Me");
        messages.put(but_login, "Login");
        messages.put(but_submit, "Submit");
        messages.put(but_quit, "Quit");
        messages.put(but_back, "Back");
        messages.put(but_query, "Query");
        messages.put(but_charge, "Charge");
        messages.put(but_option, "Setting");
        messages.put(but_register, "Register");
        messages.put(but_logout, "Logout");
        messages.put(but_confirm, "Confirm");
        messages.put(lang_en, "English");
        messages.put(lang_zh_cn, "Chinese");
        messages.put(str_callee, "Telephone Cost");
        messages.put(str_charge, "User Charge");
        messages.put(str_alert, "Operation Alert");
        messages.put(str_preCharge, "User Charge confirm?");
    }
}
